home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / renderCreateNode.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  10.2 KB  |  321 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // $RCSfile: renderCreateNode.mel $
  19. // $Revision: /main/10 $
  20. // $Date: 2000/02/25 13:50:29 $
  21. //
  22. // Alias|Wavefront Script File MODIFY THIS AT YOUR OWN RISK
  23. //
  24. //  Creation Date:  20 August 1996
  25. //  Author:         sw, cdt
  26. //
  27. //  Procedure Name:
  28. //      createRenderNode
  29. //
  30. //  Description:
  31. //        Procedure to popup the render creation window.
  32. //
  33. //  Input Arguments:
  34. //        A flag specifying which types of render nodes to create.
  35. //        Currently "-all", "-allWithTexturesUp", "-allWithShadersUp", 
  36. //        "-allWithLightsUp", "-textures", "-shadersSG", "-shaders", 
  37. //        "-lights", "-utilities" are supported.
  38. //
  39. //      The command to run after the a node has been created. The name
  40. //      of the created node will substituted "%node" in the command
  41. //      string. If an empty string is passed for the command nothing
  42. //      will be done. Currently the command is only attached to the
  43. //      buttons in the texture tab.
  44. //
  45. //        If a command is specified the createRenderNode window will be
  46. //        closed.
  47. //
  48. //  Return Value:
  49. //      None.
  50. //
  51. //////////////////////////////////////////////////////////////////////
  52. //
  53. //  Procedure Name:
  54. //      createRenderNodeCB
  55. //
  56. //  Description:
  57. //        Procedure to create the node classified as specifed by the inputs
  58. //
  59. //  Input Arguments:
  60. //        $as - 
  61. //        A flag specifying which how to classify the node created.
  62. //        Choices:
  63. //            -as2DTexture : 2d textures
  64. //            -as3DTexture : 3d textures
  65. //            -asEnvTexture : Environment textures
  66. //            -asShader : as a shader
  67. //            -asLight : as a light
  68. //            -asUtility : as a rendering utility node
  69. //
  70. //      $flag - 
  71. //            A secondary flag used to make decisions in combination with $as.
  72. //            Choices:
  73. //                -asNoShadingGroup : for materials; create without a shading group
  74. //                -asDisplacement : for anything; map the created node 
  75. //                    to a displacement material.
  76. //                -asUtility : for anything; do whatever the $as flag says,
  77. //                    but also classify as a utility
  78. //                -asPostProcess : for any postprocess node
  79. //
  80. //        $type - 
  81. //            The type of node to be created.
  82. //
  83. //        $command - 
  84. //            A command entered by the user when invoking createRenderNode.
  85. //        The command will substitute the string %node with the name of the
  86. //        node it creates.  createRenderWindow will be closed if a command
  87. //        is not the null string ("").
  88. //
  89. //  Return Value:
  90. //      None.
  91. //
  92.  
  93. global proc string renderCreateNode(
  94.     string $as, string $flag, string $type, string $command,
  95.     int $projection, int $stencil, int $placement, int $shadingGroup,
  96.     int $createAndDrop, string $editor)
  97. {
  98.     string $node;
  99.     string $cmd;
  100.     string $temp;
  101.     string $image;
  102.     if( $type == "fluidTexture3D" ){
  103.         $placement = false;
  104.     }
  105.     if ($as == "-asTexture") {
  106.  
  107.         $cmd = "shadingNode -asTexture "+$type;
  108.         $node = `evalEcho $cmd`;
  109.     }
  110.     else if ($as == "-as2DTexture") {
  111.  
  112.         if ($projection) {
  113.             $cmd = "shadingNode -asTexture projection";
  114.             $node = `evalEcho $cmd`;
  115.  
  116.             $cmd = "shadingNode -asTexture "+$type;
  117.             $image = `evalEcho $cmd`;
  118.  
  119.             $cmd = "shadingNode -asUtility place3dTexture";
  120.             string $place3d = `evalEcho $cmd`;
  121.  
  122.             $cmd = ("connectAttr "+$place3d+".wim[0] "+$node+".pm");
  123.             evalEcho $cmd;
  124.             
  125.             $cmd = ("connectAttr "+$image+".outColor "+$node+".image");
  126.             evalEcho $cmd;
  127.  
  128.             if ($placement) {
  129.                 $cmd = "shadingNode -asUtility place2dTexture";
  130.                 string $place2d = `evalEcho $cmd`;
  131.  
  132.                 // Correct #repeats for certain 2d textures
  133.                 if ($type == "checker" || $type == "bulge" || 
  134.                     $type == "cloth" || $type == "grid") {
  135.                     setAttr ($place2d + ".repeatU") 4;
  136.                     setAttr ($place2d + ".repeatV") 4;
  137.                 } else if ($type == "file") {
  138.                     fileTexturePlacementConnect $image $place2d;
  139.                 } 
  140.                 $cmd = ("connectAttr "+$place2d+".outUV "+$image+".uv");
  141.                 evalEcho $cmd;
  142.                 $cmd = ("connectAttr "+$place2d+".outUvFilterSize "+$image+".uvFilterSize");
  143.                 evalEcho $cmd;
  144.             }
  145.         }
  146.         else if ($stencil) {
  147.             $cmd = "shadingNode -asUtility stencil";
  148.             $node = `evalEcho $cmd`;
  149.  
  150.             $cmd = "shadingNode -asTexture "+$type;
  151.             $image = `evalEcho $cmd`;
  152.             
  153.             $cmd = ("connectAttr "+$image+".outColor "+$node+".image");
  154.             evalEcho $cmd;
  155.  
  156.             if ($placement) {
  157.                 $cmd = "shadingNode -asUtility place2dTexture";
  158.                 string $place2d = `evalEcho $cmd`;
  159.  
  160.                 $cmd = "shadingNode -asUtility place2dTexture";
  161.                 string $placeStencil = `evalEcho $cmd`;
  162.                 
  163.                 // Correct #repeats for certain 2d textures
  164.                 if ($type == "checker" || $type == "bulge" || 
  165.                     $type == "cloth" || $type == "grid") {
  166.                     setAttr ($place2d + ".repeatU") 4;
  167.                     setAttr ($place2d + ".repeatV") 4;        
  168.                 } 
  169.                 else if ($type == "file") {
  170.                     // special connections for file texture
  171.                     fileTexturePlacementConnect $image $place2d;
  172.                 }
  173.                 // connect texture placement
  174.                 $cmd = ("connectAttr "+$place2d+".outUV "+$image+".uv");
  175.                 evalEcho $cmd;
  176.                 $cmd = ("connectAttr "+$place2d+".outUvFilterSize "+$image+".uvFilterSize");
  177.                 evalEcho $cmd;
  178.                 $cmd = ("connectAttr "+$placeStencil+".outUV "+$node+".uv");
  179.                 evalEcho $cmd;
  180.                 $cmd = ("connectAttr "+$placeStencil+".outUvFilterSize "+$node+".uvFilterSize");
  181.                 evalEcho $cmd;
  182.                 // redefine UV space for input texture
  183.                 $cmd = ("connectAttr "+$placeStencil+".outUV "+$place2d+".uv");
  184.                 evalEcho $cmd;
  185.                 $cmd = ("connectAttr "+$placeStencil+".outUvFilterSize "+$place2d+".uvFilterSize");
  186.                 evalEcho $cmd;
  187.             }
  188.         }
  189.         else {
  190.             $cmd = "shadingNode -asTexture "+$type;
  191.             $node = `evalEcho $cmd`;
  192.             $image = $node;
  193.             
  194.             if ($placement) {
  195.                 $cmd = "shadingNode -asUtility place2dTexture";
  196.                 string $place2d = `evalEcho $cmd`;
  197.                 
  198.                 // Correct #repeats for certain 2d textures
  199.                 if ($type == "checker" || $type == "bulge" || 
  200.                     $type == "cloth" || $type == "grid") {
  201.                     setAttr ($place2d + ".repeatU") 4;
  202.                     setAttr ($place2d + ".repeatV") 4;        
  203.                 } else if ($type == "file") {
  204.                     fileTexturePlacementConnect $node $place2d;
  205.                 } 
  206.                 $cmd = ("connectAttr "+$place2d+".outUV "+$node+".uv");
  207.                 evalEcho $cmd;
  208.                 $cmd = ("connectAttr "+$place2d+".outUvFilterSize "+$node+".uvFilterSize");
  209.                 evalEcho $cmd;
  210.             }
  211.         }
  212.     }
  213.     else if ($as == "-as3DTexture") {
  214.         // Warning messsage that a projection node will not be created. 
  215.         if ($projection)
  216.             warning "Projection will not be created for solid textures.";
  217.  
  218.         $cmd = "shadingNode -asTexture "+$type;
  219.         $node = `evalEcho $cmd`;
  220.         $image = $node;
  221.  
  222.         if ($placement) {
  223.             $cmd = "shadingNode -asUtility place3dTexture";
  224.             string $place3d = `evalEcho $cmd`;
  225.  
  226.             $cmd = ("connectAttr "+$place3d+".wim[0] "+$node+".pm");
  227.             evalEcho $cmd;
  228.         }
  229.     }
  230.     else if ($as == "-asEnvTexture") {
  231.         // Warning messsage that a projection node will not be created.
  232.         if ($projection)
  233.             warning "Projection will not be created for environment textures.";
  234.  
  235.         $cmd = "shadingNode -asTexture "+$type;
  236.         $node = `evalEcho $cmd`;
  237.         $image = $node;
  238.  
  239.         if ($placement) {
  240.             $cmd = "shadingNode -asUtility place3dTexture";
  241.             string $place3d = `evalEcho $cmd`;
  242.  
  243.             // Connect the placement matrix
  244.             $cmd = ("connectAttr "+$place3d+".wim[0] "+$node+".pm");
  245.             evalEcho $cmd;
  246.  
  247.         }
  248.     }
  249.     else if ($as == "-asShader" && $shadingGroup &&
  250.              $flag != "-asNoShadingGroup") {
  251.         $cmd = ("shadingNode " + $as + " " + $type);
  252.         $node =  `evalEcho $cmd`;
  253.         $image = $node;
  254.  
  255.         $cmd = "sets -renderable true -noSurfaceShader true -empty -name "+$node+"SG";
  256.         string $group = `evalEcho $cmd`;
  257.  
  258.         if ($type == "displacementShader")
  259.         {
  260.             string $cmd = ("connectAttr -f " + $node + ".displacement " + $group + "." + $flag);
  261.             evalEcho $cmd;
  262.         }
  263.         else
  264.         {
  265.             string $cmd = ("connectAttr -f " + $node + ".outColor " + $group + "." + $flag);
  266.             evalEcho $cmd;
  267.             if( $type == "oceanShader" && $flag == "surfaceShader" ){
  268.                 // additionally hook up to displacement
  269.                 string $cmd = ("connectAttr -f " + $node + ".displacement " + $group + ".displacementShader");
  270.                 evalEcho $cmd;
  271.                 $cmd = ("connectAttr -f time1.outTime " + $node + ".time");
  272.                 evalEcho $cmd;
  273.             }
  274.         }
  275.     }
  276.     else if ($as == "-asLight") 
  277.     {
  278.         $cmd = ("shadingNode " + $as + " " + $type);
  279.         string $parent = `evalEcho $cmd`;
  280.         string $children[] = `listRelatives -children $parent`;
  281.         $node = $children[0];
  282.         $image = $node;
  283.     } 
  284.     else {
  285.         $cmd = ("shadingNode " + $as + " " + $type);
  286.         $node =  `evalEcho $cmd`;
  287.         $image = $node;
  288.     }
  289.  
  290.     if ($flag == "-asDisplacement") {
  291.         $cmd = "shadingNode -asShader displacementShader";
  292.         string $disp = `evalEcho $cmd`;
  293.  
  294.         $cmd = ("connectAttr " + $node+".outAlpha " + $disp+".displacement");
  295.         evalEcho $cmd;
  296.  
  297.         // now, reassign $node to be the displacement node
  298.         $node=$disp;
  299.     }
  300.     if( ($type == "fluidTexture3D" || $type == "fluidTexture2D" || $type == "fluidShape" ) && size($image) > 0){
  301.     
  302.         $cmd = ("connectAttr time1.outTime " + $image+".currentTime");
  303.         evalEcho $cmd;
  304.     }
  305.  
  306.     select $node;
  307.  
  308.     if ($command != "") {
  309.         $cmd = substitute("%node",$command,$node);
  310.         evalEcho $cmd;
  311.  
  312.         window -e -vis false createRenderNodeWindow;
  313.     }
  314.  
  315.     if($createAndDrop != 0) {
  316.         hyperShade -rcd $node $editor;
  317.     }
  318.  
  319.     return $node;
  320. }
  321.